package com.lw.common.web.controller;

import java.io.Serializable;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;

import com.lw.common.basemodel.Json;
import com.lw.common.core.service.BaseServiceI;
import com.lw.common.web.controller.base.BasicController;

import io.swagger.annotations.ApiParam;

/**
 * 
 * @ClassName: BaseFormController
 * @Description:(控制类)
 * @author 刘伟
 * @date 2015-11-9 下午2:21:45
 * 
 */
public abstract class BaseController<M, ID extends Serializable> extends BasicController
		implements BaseControllerI<M, ID> {
	protected final Logger logger = LoggerFactory.getLogger(getClass());

	public abstract BaseServiceI<M, ID> getBaseService();

	@RequestMapping(value = "/deleteByPrimaryKey", method = RequestMethod.POST)
	public Json deleteByPrimaryKey(@ApiParam(value = "id") @RequestParam(required = true) ID id) {

		return getBaseService().deleteByPrimaryKey(id) > 0 ? setSimpleSuccess(id) : setFailed();
	}

	@RequestMapping(value = "/insert", method = RequestMethod.POST)
	public Json insert(M record) {

		return getBaseService().insert(record) > 0 ? setSimpleSuccess(record) : setFailed();
	}

	@RequestMapping(value = "/insertSelective", method = RequestMethod.POST)
	public Json insertSelective(M record) {

		return getBaseService().insertSelective(record) > 0 ? setSimpleSuccess(record) : setFailed();
	}

	@RequestMapping(value = "/selectByPrimaryKey", method = RequestMethod.GET)
	public M selectByPrimaryKey(@ApiParam(value = "id") @RequestParam(value = "id", required = true) ID id) {
		return getBaseService().selectByPrimaryKey(id);
	}

	@RequestMapping(value = "/updateByPrimaryKeySelective", method = RequestMethod.POST)
	public Json updateByPrimaryKeySelective(M record) {

		return getBaseService().updateByPrimaryKeySelective(record) > 0 ? setSimpleSuccess(record) : setFailed();
	}

	@RequestMapping(value = "/updateByPrimaryKey", method = RequestMethod.POST)
	public Json updateByPrimaryKey(M record) {

		return getBaseService().updateByPrimaryKey(record) > 0 ? setSimpleSuccess(record) : setFailed();
	}

}
